/*********************************************************************************
 *      Copyright:  (C) 2023 Lin XinCheng
 *                  All rights reserved.
 *
 *       Filename:  key_app.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(2023年07月20日)
 *         Author:  Lin XinCheng <1481155734@qq.com>
 *      ChangeLog:  1, Release initial version on "2023年07月20日 16时57分03秒"
 *                 
 ********************************************************************************/

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/*
 * ./led_App /dev/key0
 */

#define KEY0VALUE	0xF0
#define INVAKEY		0x00


int main (int argc, char **argv)
{
	int fd;
	unsigned char keyvalue;

	//打开文件
	fd = open("/dev/key0", O_RDWR);
	if ( fd < 0 )
	{
		printf("open /dev/key0 failure\n");
		return -1;
	}

	while(1)
	{
		//读文件
		read(fd, &keyvalue, sizeof(keyvalue));
	
	if(keyvalue == KEY0VALUE)
	{
		printf("KEY0 Press, value = %#X\r\n",keyvalue);
	}

	}
	close(fd);

	return 0;
} 

